<?php

abstract class AbstractOrganizationalProperty
{
  
  /**
   * @var OrganizationalUnit
   */
  protected $unit;
  
  /**
   * @var OrganizationalProperty
   */
  protected $property;
  
  /**
   * @var AbstractOrganizationalPropertyType
   */
  protected $type;
  
  /**
   * @var array
   */
  protected $values;
  
  /**
   * @var string
   */
  protected $value_type;

  public function __construct (OrganizationalUnit $unit, OrganizationalProperty $property, AbstractOrganizationalPropertyType $type, $values)
  {
    $this->unit = $unit;
    $this->property = $property;
    $this->type = $type;
    $this->values = $values;
    
    if (isset($this->values['unit']) && isset($this->values['entity']))
    {
      throw new LogicException();
    }
    elseif (isset($this->values['unit']))
    {
      $this->value_type = 'unit';
    }
    else
    {
      $this->value_type = 'entity';
    }
  }

  public function __toString ()
  {
    return $this->property->getName();
  }
  
  public function getPropertyDescription() {
    
    return $this->property->getDescription();
  }

  public function getValue ()
  {
    reset($this->values[$this->value_type]);
    return current($this->values[$this->value_type]);
  }

  public function hasManyValues ()
  {
    return count($this->values[$this->value_type]) > 1;
  }

  public function getValues ()
  {
    return $this->values[$this->value_type];
  }

  public function getProperty ()
  {
    return $this->property;
  }

  public function getDisplayValue ()
  {
    return $this->type->getDisplayValue($this->value);
  }
  
  public function getValueType() {
    return $this->value_type;
  }
  
  public function getOrganizationalUnit() {
    return $this->unit;
  }

//  abstract public function getFormWidgets ($options = array());
//
//  abstract public function getFormValidators ($options = array());
//
//  abstract public function getFormWidgetIds ();

  //  public function getFormWidget($options=array()) {
//    return $this->type->getFormWidget($options);
//  } 
//  
//  public function getFormWidgetValidator($options=array()) {
//    return $this->type->getFormWidgetValidator($options);
//  }
//  
//  public function getFormWidgetLabel() {
//    return $this->property->getDescription();
//  }
//  
//  public function getFormWidgetId() {
//    return $this->property->getName();
//  }
}